import { ref, watch } from "vue";
import { areaList } from "@vant/area-data";
import { tr } from "element-plus/es/locales.mjs";

interface OptionColumn {
  text: string;
  value: string;
}
interface Rule {
  required: boolean;
  message?: string;
  pattern?: any;
}
interface ListItem {
  value: string | any;
  type: string;
  label: string;
  names: string;
  rules: Rule[];
  component: string;
  showPicker?: boolean;
  columns?: OptionColumn[] | any;
  maxlength?: number;
  showError?: boolean;
  tip?: string;
  minDate?: Date;
  maxDate?: Date;
  max?: number;
  direction?: string;
  range1Label?: string;
  range2Label?: string;
  preTip?: string;
  canDel?: true;
  delWith?: string;
  remoteMethod?: Function;
  loading?: boolean;
  id?: number | string;
  append?: boolean;
  divide?: boolean;
  Vandivide?: boolean;
  show?: boolean;
  isNotVal?: boolean;
  withInput?: boolean;
  inputVal?: string;
  reflectLabel?: string;
  tips?: string[];
  showPicker1?: boolean;
  asTitle?: boolean;
  mainTitle?: boolean;
  useElement?: boolean;
}

interface TitleListItem {
  label: string;

  tip?: string;
  list: ListItem[];
}
import apis from "../../api/index";
const { selectCommonConfigDetail, selectUniversityDetail } = apis;
//name label
const getselectCommonConfigDetail = async (types: any) => {
  const res: any = await selectCommonConfigDetail({
    type: types,
  });
  const extractedData = res.data.map((job) => ({
    name: job.value,
    label: job.label,
  }));
  return extractedData;
};

//text value
const getselectCommonConfigDetailText = async (types: any) => {
  const res: any = await selectCommonConfigDetail({
    type: types,
  });
  const extractedData = res.data.map((job) => ({
    text: job.value,
    value: job.label,
  }));
  return extractedData;
};

const POST_SUBJECT = await getselectCommonConfigDetail("POST_SUBJECT"); //应聘岗位
const INTENTION_GRADE = await getselectCommonConfigDetail("INTENTION_GRADE"); //意向年级
const INTENTION_SUBJECT = await getselectCommonConfigDetail(
  "INTENTION_SUBJECT"
); //意向学科
const INTENTION_PlACE = await getselectCommonConfigDetail("INTENTION_PlACE"); //意向工作地点
const EMPLOYMENT_STANDARDS = await getselectCommonConfigDetail(
  "EMPLOYMENT_STANDARDS"
); //应聘信息来源
const INFORMATION_SOURCE = await getselectCommonConfigDetail(
  "INFORMATION_SOURCE"
); //应聘信息来源

const COMPETITION = await getselectCommonConfigDetailText("COMPETITION"); //竞赛类别
const LANGUAGES = await getselectCommonConfigDetailText("LANGUAGES"); //语言能力

//getselectCommonConfigDetail();
const getUniversityDetail = async (schoolName: string) => {
  if (schoolName === "") {
    // return [];
    schoolName = "北京";
  }
  const data: any = await selectUniversityDetail({ schoolName: schoolName });
  if (data && data.code === "10000") {
    const list = data.data.map((el) => {
      return {
        label: el.universityName,
        value: el.universityName,
      };
    });
    return list;
  } else {
    return [];
  }
};
const getShcool = async (val: string, v: ListItem) => {
  const id = v.id;
  titleList.value.forEach((el: TitleListItem) => {
    el.list.forEach(async (item: ListItem) => {
      // if (item.id)
      if (item.id === id) {
        v.columns = await getUniversityDetail(val);
      }
    });
  });
};

const practiceList = ref<ListItem[]>([
  {
    names: "workPlace",
    preTip: "实习经历-1",
    show: true,
    value: "",
    type: "",
    label: "公司名称",
    rules: [{ required: true }],
    component: "input",
    delWith: "pratice",
  },
  {
    names: "workPost",
    value: "",
    type: "",
    show: true,
    label: "职位",
    rules: [{ required: true }],
    component: "input",
    delWith: "pratice",
  },
  {
    names: "workStartDate",
    value: [[], []],
    type: "",
    show: true,
    label: "起止时间",
    rules: [{ required: true }],
    component: "dateRange",
    range1Label: "开始时间",
    range2Label: "结束时间",
    delWith: "pratice",
    minDate: new Date(1980, 1, 1),
    maxDate: new Date(),
    showPicker1: false,
    showPicker: false,
  },
  {
    names: "workDetail",
    value: "",
    show: true,
    type: "",
    label: "工作（实习）/培训内容",
    Vandivide: true,
    rules: [{ required: false }],
    component: "textarea",

    delWith: "pratice",
  },
]);

const educationList = ref<ListItem[]>([
  {
    value: "",
    names: "dels",
    type: "",
    label: "删除",
    component: "del",
    delWith: "master",
    show: true,
    isNotVal: true,
    rules: [{ required: false }],
  },
  {
    names: "schoolName",
    preTip: "教育经历-硕士",
    show: true,
    delWith: "master",
    columns: [],
    value: "",
    type: "",
    label: "学校名称",
    rules: [{ required: true }],
    component: "remote",
    tip: "请输入学校全称，国内院校请输入中文名，如：哈尔滨工业大学（深圳）；海外院校请输入英文名，如：Columbia University",
  },
  {
    names: "educationalStartTime",
    show: true,
    value: [[], []],
    type: "",
    label: "起止时间",
    rules: [{ required: true }],
    component: "dateRange",
    range1Label: "开始时间",
    range2Label: "结束时间",
    delWith: "master",
    minDate: new Date(1980, 1, 1),
    maxDate: new Date(),
    showPicker1: false,
    showPicker: false,
  },
  {
    names: "schoolDepartment",
    show: true,
    value: "",
    type: "",
    label: "院系",
    rules: [{ required: true }],
    component: "input",
    delWith: "master",
  },
  {
    names: "specialty",
    show: true,
    value: "",
    type: "",
    label: "专业",
    Vandivide: true,
    rules: [{ required: true }],
    component: "input",
    delWith: "master",
  },

  {
    names: "dels",
    value: "",
    type: "",
    label: "删除",
    component: "del",
    delWith: "doctor",
    show: true,
    isNotVal: true,
    rules: [{ required: false }],
  },
  {
    names: "schoolName",
    preTip: "教育经历-博士",
    show: true,
    delWith: "doctor",
    columns: [],
    value: "",
    type: "",
    label: "学校名称",
    rules: [{ required: true }],
    component: "remote",
    tip: "请输入学校全称，国内院校请输入中文名，如：哈尔滨工业大学（深圳）；海外院校请输入英文名，如：Columbia University",
  },
  {
    names: "educationalStartTime",
    show: true,
    value: [[], []],
    type: "",
    label: "起止时间",
    rules: [{ required: true }],
    component: "dateRange",
    range1Label: "开始时间",
    range2Label: "结束时间",
    delWith: "doctor",
    minDate: new Date(1980, 1, 1),
    maxDate: new Date(),
    showPicker1: false,
    showPicker: false,
  },
  {
    names: "schoolDepartment",
    show: true,
    value: "",
    type: "",
    label: "院系",
    rules: [{ required: true }],
    component: "input",
    delWith: "doctor",
  },
  {
    names: "specialty",
    show: true,
    value: "",
    type: "",
    label: "专业",
    Vandivide: true,
    rules: [{ required: true }],
    component: "input",
    delWith: "doctor",
  },
]);

const competitionList = ref<ListItem[]>([
  {
    names: "competitionType",
    preTip: "奖项-1",
    show: true,
    value: "",
    type: "",
    label: "竞赛类别",
    rules: [{ required: true }],
    component: "select",
    delWith: "competition",
    columns: COMPETITION,
  },

  {
    names: "competitionLevel",
    value: "",
    show: true,
    type: "",
    label: "等级/奖项",
    Vandivide: true,
    rules: [{ required: true }],
    component: "textarea",
    delWith: "competition",
  },
]);

const familyList = ref<ListItem[]>([
  {
    names: "relation",
    preTip: "家庭成员-1",
    show: true,
    value: "",
    type: "",
    label: "关系",
    rules: [{ required: true }],
    component: "input",
    delWith: "family",
  },
  {
    names: "name",
    show: true,
    value: "",
    type: "",
    label: "姓名",
    rules: [{ required: true }],
    component: "input",
    delWith: "family",
  },
  {
    names: "age",
    show: true,
    value: "",
    type: "number",
    label: "年龄",
    rules: [{ required: true }],
    component: "input",
    delWith: "family",
  },
  {
    names: "phone",
    show: true,
    value: "",
    type: "number",
    label: "联系电话",
    rules: [
      {
        required: true,
        pattern:
          /^1(3[0-9]|4[5-9]|5[0-35-9]|6[5-6]|7[0-8]|8[0-9]|9[1-35-9])\d{8}$/,
      },
    ],
    component: "input",
    delWith: "family",
  },
  {
    names: "workPlace",
    show: true,
    value: "",
    type: "",
    label: "工作单位",
    rules: [{ required: true }],
    component: "input",
    delWith: "family",
  },
  {
    names: "occupation",
    show: true,
    value: "",
    type: "",
    label: "职务",
    rules: [{ required: true }],
    component: "input",
    delWith: "family",
  },
]);

const count = ref<number>(0);
const educationCount = ref<number>(0);
const competitionCount = ref<number>(0);
const familyCount = ref<number>(0);
const getIndex = (val: number, items: ListItem): number => {
  return titleList.value[val].list.findIndex((el) => {
    return el.id === items.id;
  });
};

const addList = (items: ListItem) => {
  let sign = Math.random() + "";

  if (items.delWith == "pritice") {
    let index = getIndex(3, items);
    appendPratice(sign, items, index, 3);
  }
  if (items.delWith == "masters") {
    let index = getIndex(2, items);
    appendEducation(sign, items, index);
  }

  if (items.delWith == "competitions") {
    let index = getIndex(4, items);
    appendCompetitions(sign, items, index, 4);
  }
  if (items.delWith == "langs") {
    appendLang(items, 5);
  }

  if (items.delWith == "familys") {
    appendFamily(sign, items, 6);
  }
};

const doReduce = (item: ListItem) => {
  let sign = item.delWith?.split("-")[0];
  if (sign === "master" || sign == "doctor") {
    educationCount.value--;
    titleList.value[2].list = titleList.value[2].list.filter(
      (el) => el.delWith != item.delWith
    );
  }
  if (sign === "competition") {
    competitionCount.value--;
    titleList.value[4].list = titleList.value[4].list.filter(
      (el) => el.delWith != item.delWith
    );
  }
  if (sign === "family") {
    familyCount.value--;
    titleList.value[6].list = titleList.value[6].list.filter(
      (el) => el.delWith != item.delWith
    );
    return;
  }
  if (sign === "lang") {
    titleList.value[5].list.forEach((el) => {
      el.show = !el.show;
    });
  }
  if (sign === "pratice") {
    count.value--;
    titleList.value[3].list = titleList.value[3].list.filter(
      (el) => el.delWith != item.delWith
    );
  }
};

const appendLang = (item: ListItem, current: number) => {
  titleList.value[current].list.forEach((el) => {
    el.show = !el.show;
    if (el.component === "assembly") {
      el.value = ["", ""];
    }
  });
};

const appendCompetitions = (
  sign: string,
  items: ListItem,
  index: number,
  current: number
) => {
  let newlist = JSON.parse(JSON.stringify(competitionList.value));
  newlist.forEach((el: ListItem) => {
    el.delWith = "competition-" + sign;
    el.value = "";
  });
  newlist[0].preTip = "奖项-" + (competitionCount.value + 2);
  newlist = [
    {
      value: "",
      type: "",
      names: "dels",
      label: "删除",
      component: "del",
      Vandivide: true,
      delWith: "competition-" + sign,
      show: true,
      isNotVal: true,
    },
    ...newlist,
  ];

  competitionCount.value++;
  titleList.value[current].list.splice(index, 0, ...newlist);
};

const appendFamily = (sign: string, items: ListItem, current: number) => {
  const index = titleList.value[3].list.findIndex((el) => {
    return el.id === items.id;
  });
  let newlist = JSON.parse(JSON.stringify(familyList.value));
  newlist.forEach((el: ListItem) => {
    el.delWith = "family-" + sign;
    el.value = "";
  });
  newlist[0].preTip = "成员-" + (familyCount.value + 2);
  newlist = [
    {
      value: "",
      type: "",
      names: "dels",
      label: "删除",
      component: "del",
      delWith: "family-" + sign,
      show: true,
      isNotVal: true,
    },
    ...newlist,
  ];
  familyCount.value++;
  titleList.value[current].list.splice(index, 0, ...newlist);
};

const appendPratice = (
  sign: string,
  items: ListItem,
  index: number,
  current: number
) => {
  let newlist = JSON.parse(JSON.stringify(practiceList.value));
  newlist.forEach((el: ListItem) => {
    el.delWith = "pratice-" + sign;
    el.value = "";
  });
  newlist[0].preTip = "实习经历-" + (count.value + 2);
  newlist[2].value = [];
  newlist = [
    {
      value: "",
      type: "",
      name: "dels",
      label: "删除",
      component: "del",
      delWith: "pratice-" + sign,
      show: true,
      Vandivide: true,
      isNotVal: true,
    },
    ...newlist,
  ];

  count.value++;
  titleList.value[current].list.splice(index, 0, ...newlist);
};
const appendEducation = (sign: string, items: ListItem, index: number) => {
  let newlist = JSON.parse(JSON.stringify(educationList.value));
  if (educationCount.value === 0) {
    newlist = newlist.filter((item: ListItem) => item.delWith == "master");
    educationCount.value = 1;
  } else {
    newlist = newlist.filter((item: ListItem) => item.delWith == "doctor");
    educationCount.value = 2;
  }
  titleList.value[2].list.splice(index, 0, ...newlist);
};
watch(count, (val) => {
  titleList.value[3].list.forEach((el) => {
    if (el.delWith == "pritice" && val === 3) {
      el.show = false;
    } else {
      el.show = true;
    }
  });
});
watch(competitionCount, (val) => {
  titleList.value[4].list.forEach((el) => {
    if (el.delWith == "competitions" && val === 4) {
      el.show = false;
    } else {
      el.show = true;
    }
  });
});
watch(familyCount, (val) => {
  titleList.value[6].list.forEach((el) => {
    if (el.delWith == "familys" && val === 4) {
      el.show = false;
    } else {
      el.show = true;
    }
  });
});

watch(educationCount, (val) => {
  let list = titleList.value[2].list;
  list.forEach((el) => {
    if (val === 2 && el.delWith == "masters") {
      el.show = false;
    } else {
      el.show = true;
    }
    if (el.delWith == "master" && el.component === "del" && val === 2) {
      el.show = false;
    }
  });
});

const titleList = ref<TitleListItem[]>([
  {
    label: "基础信息",
    list: [
      {
        names: "imgae",
        label: "个人照片",
        type: "upload",
        rules: [{ required: false }],
        Vandivide: true,
        component: "upload",
        value: [],
        tips: ["请将文件大小控制在2M以内。"],
      },
      {
        names: "userName",
        value: "",
        type: "",
        label: "姓名",
        rules: [{ required: true }],
        component: "input",
      },
      {
        value: "",
        type: "",
        label: "性别",
        names: "sex",
        rules: [{ required: true, message: "" }],
        component: "radio",
        direction: "horizontal",
        columns: [
          { label: "男", name: "0" },
          { label: "女", name: "1" },
        ],
      },
      // {
      //   names: "certificateType",
      //   value: "",
      //   type: "",
      //   label: "证件类型",
      //   rules: [{ required: true }],
      //   component: "select",
      //   showPicker: false,
      //   columns: [
      //     { text: "中国-居民身份证", value: "中国-居民身份证" },
      //     { text: "护照", value: "护照" },
      //     { text: "中国-港澳永久身份证", value: "中国-港澳永久身份证" },
      //     { text: "中国-台胞证", value: "中国-台胞证" },
      //     { text: "中国-港澳非永久身份证", value: "中国-港澳非永久身份证" },
      //     { text: "其他", value: "其他" },
      //   ],
      // },
      // {
      //   names: "certificateNumber",
      //   value: "",
      //   type: "",
      //   label: "证件号码",
      //   rules: [{ required: true }],
      //   component: "input",
      //   maxlength: 18,
      //   //tip: ``,
      // },
      // {
      //   names: "phone",
      //   value: "",
      //   type: "",
      //   label: "手机号码",
      //   rules: [
      //     {
      //       required: true,
      //       pattern:
      //         /^1(3[0-9]|4[5-9]|5[0-35-9]|6[5-6]|7[0-8]|8[0-9]|9[1-35-9])\d{8}$/,
      //     },
      //   ],
      //   component: "input",
      //   maxlength: 11,
      // },
      {
        names: "email",
        value: "",
        type: "",
        label: "电子邮箱",
        rules: [
          {
            required: true,
            pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
          },
        ],
        component: "input",
      },
      {
        names: "birthday",
        value: "",
        type: "",
        label: "出生日期",
        rules: [{ required: true }],
        component: "datePicker",
        showPicker: false,
        minDate: new Date(1980, 1, 1),
        maxDate: new Date(),
      },

      {
        names: "birthplace",
        value: "",
        type: "",
        label: "籍贯",
        Vandivide: true,
        rules: [{ required: true }],
        component: "area",
        columns: areaList,
      },
    ],
  },
  {
    label: "投递岗位",
    tip: "此处仅做初步了解，不代表分配的最终结果，培训期间会再次确认。",
    list: [
      {
        value: [],
        names: "intentionPostList",
        type: "",
        label: "应聘岗位科目（最多选三项）",
        rules: [{ required: true }],
        component: "checkbox",
        max: 3,
        asTitle: true,
        columns: POST_SUBJECT,
      },

      {
        names: "intentionGrade",
        value: [],
        type: "",
        label: "意向年级段（最多选两项）",
        rules: [{ required: true }],
        component: "checkbox",
        asTitle: true,
        max: 2,
        columns: INTENTION_GRADE,
      },
      {
        names: "intentionSubject",
        value: [],
        type: "",
        label: "意向学科（最多选三项）",
        rules: [{ required: true }],
        component: "checkbox",
        asTitle: true,
        max: 3,
        columns: INTENTION_SUBJECT,
      },
      {
        names: "intentionPlace",
        value: [],
        type: "",
        label: "意向工作地点（最多选三项）",
        rules: [{ required: true }],
        component: "checkbox",
        asTitle: true,
        max: 3,
        Vandivide: true,
        columns: INTENTION_PlACE,
      },
      // {
      //   names: "",
      //   value: [],
      //   type: "",
      //   label: "工作地点是否服从分配",
      //   rules: [{ required: true }],
      //   component: "radio",
      //   direction: "horizontal",
      //   columns: [
      //     { label: "是", name: "1" },
      //     { label: "否", name: "2" },
      //   ],
      // },
    ],
  },
  {
    label: "教育经历",
    list: [
      {
        names: "schoolName",
        preTip: "教育经历-高中",
        value: "",
        type: "",
        label: "学校名称",
        rules: [{ required: true }],
        component: "input",
        tip: "请输入学校全称，国内院校请输入中文名，如：哈尔滨工业大学（深圳）；海外院校请输入英文名，如：Columbia University",
      },
      {
        names: "educationalStartTime",
        value: [[], []],
        type: "",
        label: "起止时间",
        rules: [{ required: true }],
        component: "dateRange",
        range1Label: "开始时间",
        range2Label: "结束时间",
        minDate: new Date(1980, 1, 1),
        maxDate: new Date(),
        showPicker1: false,
        showPicker: false,
      },

      {
        names: "schoolName",
        preTip: "教育经历-本科",
        columns: [],
        value: "",
        type: "",
        label: "学校名称",
        rules: [{ required: true }],
        component: "remote",
        tip: "请输入学校全称，国内院校请输入中文名，如：哈尔滨工业大学（深圳）；海外院校请输入英文名，如：Columbia University",
      },
      {
        names: "educationalStartTime",
        value: [[], []],
        type: "",
        label: "起止时间",
        rules: [{ required: true }],
        component: "dateRange",
        range1Label: "开始时间",
        range2Label: "结束时间",
        minDate: new Date(1980, 1, 1),
        maxDate: new Date(),
        showPicker1: false,
        showPicker: false,
      },
      {
        names: "schoolDepartment",
        value: "",
        type: "",
        label: "院系",
        rules: [{ required: true }],
        component: "input",
      },
      {
        names: "specialty",
        value: "",
        type: "",
        label: "专业",
        Vandivide: true,
        rules: [{ required: true }],
        component: "input",
      },

      {
        names: "dels",
        value: "",
        type: "",
        label: "添加学历",
        component: "add",
        isNotVal: true,
        delWith: "masters",
        Vandivide: true,
        rules: [{ required: false }],
      },
    ],
  },
  {
    label: "工作（实习）/培训经历",
    list: [
      {
        names: "dels",
        value: "",
        type: "",
        label: "删除",
        component: "del",
        delWith: "pratice",
        show: true,
        isNotVal: true,
        Vandivide: true,
        rules: [{ required: false }],
      },
      ...practiceList.value,
      {
        names: "dels",
        value: "",
        type: "",
        label: "添加经历",
        Vandivide: true,
        delWith: "pritice",
        component: "add",
        isNotVal: true,
        rules: [{ required: false }],
      },
    ],
  },
  {
    label: "竞赛获奖经历",
    list: [
      {
        names: "dels",
        value: "",
        type: "",
        label: "删除",
        component: "del",
        delWith: "competition",
        Vandivide: true,
        show: true,
        isNotVal: true,
        rules: [{ required: false }],
      },
      ...competitionList.value,
      {
        names: "dels",
        value: "",
        type: "",
        label: "添加竞赛获奖经历",
        Vandivide: true,
        delWith: "competitions",
        component: "add",
        isNotVal: true,
        rules: [{ required: false }],
      },
    ],
  },
  {
    label: "语言能力",
    list: [
      {
        names: "dels",
        value: "",
        type: "",
        label: "删除",
        component: "del",
        delWith: "lang",
        show: false,
        isNotVal: true,
        rules: [{ required: false }],
      },
      {
        names: "foreignLanguagesGrade",
        show: false,
        value: ["", ""],
        type: "",
        label: "外语考试/等级",
        component: "assembly",
        rules: [{ required: true }],
        delWith: "lang",
        columns: LANGUAGES,
      },
      {
        names: "dels",
        value: "",
        type: "",
        label: "添加语言能力",
        Vandivide: true,
        delWith: "langs",
        component: "add",
        show: true,
        isNotVal: true,
        rules: [{ required: false }],
      },
    ],
  },
  // {
  //   label: "家庭情况",
  //   list: [
  //     // {
  //     //     value: '',
  //     //     type: '',
  //     //     label: '家庭情况',
  //     //     component: 'divider',
  //     //     isNotVal: true
  //     // },
  //     {
  //       names: "dels",
  //       value: "",
  //       type: "",
  //       label: "删除",
  //       component: "del",
  //       delWith: "family",
  //       show: true,
  //       isNotVal: true,
  //       rules: [{ required: false }],
  //     },
  //     ...familyList.value,
  //     {
  //       names: "dels",
  //       value: "",
  //       type: "",
  //       label: "添加家庭成员",
  //       delWith: "familys",
  //       component: "add",
  //       isNotVal: true,
  //       rules: [{ required: false }],
  //     },
  //   ],
  // },
  {
    label: "",
    list: [
      {
        names: "standards",
        value: [],
        type: "",
        label: "择业倾向（按重要程度依次选择，最多选3项）",
        Vandivide: true,
        mainTitle: true,
        rules: [{ required: true }],
        component: "checkbox",
        useElement: true,
        max: 3,
        columns: EMPLOYMENT_STANDARDS,
      },
    ],
  },
  {
    label: "",
    list: [
      {
        names: "source",
        value: "",
        type: "",
        label: "应聘信息来源",
        mainTitle: true,
        rules: [{ required: true }],
        component: "radio",
        direction: "horizontal",
        Vandivide: true,
        columns: INFORMATION_SOURCE,
        withInput: true,
        inputVal: "",
        reflectLabel: "其他",
      },
    ],
  },
  {
    label: "是否内推",
    list: [
      {
        names: "isRecommends",
        value: "",
        type: "",
        label: "是否内推",
        rules: [{ required: true }],
        component: "radio",
        direction: "horizontal",
        columns: [
          { label: "是", name: "0" },
          { label: "否", name: "1" },
        ],
      },
      {
        names: "recommendsName",
        value: "",
        type: "",
        label: "内推人",
        rules: [
          {
            required: true,
          },
        ],
        component: "input",
      },
      {
        names: "recommendsPhone",
        value: "",
        type: "number",
        label: "内推人手机号",
        Vandivide: true,
        rules: [
          {
            required: true,
            pattern:
              /^1(3[0-9]|4[5-9]|5[0-35-9]|6[5-6]|7[0-8]|8[0-9]|9[1-35-9])\d{8}$/,
          },
        ],
        component: "input",
        maxlength: 11,
      },
    ],
  },
  {
    label: "",
    list: [
      {
        names: "intentionDate",
        value: "",
        type: "",
        label: "最早可入职",
        rules: [{ required: true }],
        Vandivide: true,
        component: "datePicker",
        showPicker: false,
        minDate: new Date(),
        maxDate: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 365),
      },
    ],
  },
  {
    label: "",
    list: [
      {
        names: "accessoryUrl",
        value: [],
        type: "",
        mainTitle: true,
        label: "简历附件",
        rules: [{ required: false }],
        Vandivide: true,
        component: "uploadarea",
        tips: ["请将文件大小控制在2M以内。", "附件仅支持word和pdf文档。"],
      },
    ],
  },
]);

titleList.value.forEach((item, idx) => {
  item.list.forEach((el: ListItem, index) => {
    el.showError = false;
    el.id = `${idx + 1}-${index + 1}`;
    if (el.show !== false) {
      el.show = true;
    }
  });
});

watch(
  () => titleList.value[2].list,
  (val) => {
    let counts = 0;
    let competitionCounts = 0;
    val.forEach((item) => {
      if (item.component === "del") {
        if (item.delWith?.split("-")[0] == "competition") {
          const isLast = competitionCounts == competitionCount.value;
          competitionCounts++;
          if (!isLast) {
            item.show = false;
          }
        }
        if (item.delWith?.split("-")[0] == "pratice") {
          const isLast = counts == count.value;
          counts++;
          if (!isLast) {
            item.show = false;
          }
        }
      }
    });
  },
  { deep: true }
);

watch(
  () => titleList.value[3].list,
  (val) => {
    let counts = 0;
    val.forEach((item) => {
      if (item.component === "del") {
        if (item.delWith?.split("-")[0] == "family") {
          const isLast = counts == familyCount.value;
          counts++;
          if (!isLast) {
            item.show = false;
          }
        }
      }
    });
  },
  { deep: true }
);
//监听是否内推
watch(
  () => titleList.value[8].list,
  (val) => {
    //选择否
    val[1].show = val[2].show = val[0].value !== "1";
  },
  {
    deep: true,
  }
);
export { titleList, addList, doReduce, getShcool };
export type { OptionColumn, Rule, ListItem, TitleListItem };
export const data = {
  hf: {
    math: ["1", "2", "3", "4"],
    english: ["1", "2", "3"],
    physics: ["3", "4"],
    chemistry: ["3", "4"],
  },
  wh: {
    math: ["1", "2", "3"],
    physics: ["3"],
  },
  aq: {
    math: ["1", "2", "3"],
    physics: ["3"],
  },
  mas: {
    math: ["1", "2", "3"],
    physics: ["3"],
  },
  singapore: {
    math: ["1", "2", "3"],
  },
};
